package com.itmuch.common.context;

import com.itmuch.common.feignset.hystix.QfHystrixRequestContext;

/**
 * 多库切换的上下文 含有公司的上下文信息
 * 〈一句话功能简述〉<br> 
 * 〈功能详细描述〉
 * @author Administrator
 *
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class QfContext {
    private static final ThreadLocal<QfContext> dbThredLocal = new ThreadLocal<QfContext>();
	private Long dbServerId;//zone1,zone2 对应的serverId
	private String dbServerUrl;//master的数据库url包含端口加ip
	private String dbServerUserName;//server的数据库
	private String dbServerPassword;//server的密码
	private String companyDbName;//公司的数据库
	
	/**
	 * bff的上下文只能取这个取下面的四个字段
	 */
	private String companyUuid;//公司的uuid
	private Long userId;//登录员工
	private String userUuid;//登录员工的uuid
	private String userToken;//用户token
	private String  userName;//登录员工的用户名称，目前只能被内部系统使用

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserToken() {
		return userToken;
	}

	public void setUserToken(String userToken) {
		this.userToken = userToken;
	}

	public QfContext(Long dbServerId, String dbServerUrl,
			String dbServerUserName, String dbServerPassword,String companyUuid, String companyDbName) {
		super();
		this.companyUuid = companyUuid;
		this.companyDbName = companyDbName;
		this.dbServerId = dbServerId;
		this.dbServerUrl = dbServerUrl;
		this.dbServerUserName = dbServerUserName;
		this.dbServerPassword = dbServerPassword;
	}
	
	public QfContext(){};

	
	public String getUserUuid() {
		return userUuid;
	}

	public void setUserUuid(String userUuid) {
		this.userUuid = userUuid;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	
	public Long getDbServerId() {
		return dbServerId;
	}

	public void setDbServerId(Long dbServerId) {
		this.dbServerId = dbServerId;
	}

    public String getCompanyDbName() {
		return companyDbName;
	}

	public void setCompanyDbName(String companyDbName) {
		this.companyDbName = companyDbName;
	}

	public String getDbServerUrl() {
		return dbServerUrl;
	}

	public void setDbServerUrl(String dbServerUrl) {
		this.dbServerUrl = dbServerUrl;
	}

	public static void setQfContextThreadLocal(QfContext context){
    	dbThredLocal.set(context);
    	QfHystrixRequestContext.setCrossThreadContext(context);
    }

    
     public static void removeQfContextThreadLocal(){
    	dbThredLocal.remove();
    	QfHystrixRequestContext.setCrossThreadContext(null);
    }
     
     public  static ThreadLocal<QfContext> getDbthredlocal() {
 		return dbThredLocal;
 	}
 	


	public String getDbServerUserName() {
		return dbServerUserName;
	}

	public void setDbServerUserName(String dbServerUserName) {
		this.dbServerUserName = dbServerUserName;
	}

	public String getDbServerPassword() {
		return dbServerPassword;
	}

	public void setDbServerPassword(String dbServerPassword) {
		this.dbServerPassword = dbServerPassword;
	}

	public String getCompanyUuid() {
		return companyUuid;
	}

	public void setCompanyUuid(String companyUuid) {
		this.companyUuid = companyUuid;
	}


}
